/// Created by Nazariy Jaworski Copyright (c) 2013
/// Bot program
///
/// bot.cpp - Main class of the program
///
/// To Do list:
///  - Threadsafety
///  - ...
///
/// v 0.1        03.04.2013

#include "bot.h"
#include "botui.h"
#include "globalargs.h"
#include <QTime>

Bot::Bot(int argc, char **argv) : QCoreApplication(argc, argv)
{
    isOk    = true;
    // keep it clean, use 'Init()' for extra initializations
}

static bool initialized = false; ///< Extra local object

void Bot::Init()
{
    if(!initialized)
    {
        isBusy  = false;

        // Initialization of his main objects
        myCommunicator  = new BotCommunicator(this);

        // Extra initializations
        myCommunicator->Init();
    }
}

static Bot *singletonBot = nullptr; ///< Extra local object
Bot *Bot::GetInstance()
{
    if(!singletonBot)
        singletonBot = new Bot(__argc,__argv);
    return singletonBot;
}

void Bot::SLOT_FatalError(const QString message)
{
    QString str = QTime::currentTime().toString() + " " + message;
    Q_EMIT SIGNAL_WriteToLog(str);
    isOk = false;
    quit();
}

Bot::~Bot()
{
    // Destruction of his main objects
    delete myCommunicator;
}
